# Contributor: omni <omni+alpine@hack.org>
# Maintainer: messense <messense@icloud.com>
pkgname=maturin
pkgver=1.7.4
pkgrel=0
pkgdesc="Build and publish crates with pyo3, rust-cpython and cffi bindings"
url="https://github.com/PyO3/maturin"
arch="all"
license="Apache-2.0 OR MIT"
makedepends="
	bzip2-dev
	cargo
	dbus-dev
	openssl-dev
	py3-gpep517
	py3-setuptools
	py3-setuptools-rust
	py3-wheel
	"
checkdepends="
	cargo-nextest
	libffi-dev
	patchelf
	py3-cffi
	py3-pyo
	py3-virtualenv
	python3-dev
	"
subpackages="
	$pkgname-bash-completion
	$pkgname-fish-completion
	$pkgname-zsh-completion
	py3-$pkgname-pyc
	py3-$pkgname:py3:noarch
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/PyO3/maturin/archive/v$pkgver.tar.gz
	"
options="net"

_features="--features=full,native-tls,password-storage"
# these only work in a git checkout
_test_filter='!test(~git_sdist_generator) & !test(~pyo3_mixed_include_exclude)'

case "$CARCH" in
s390x|ppc64le|loongarch64)
	# cargo-nextest not available
	options="$options !check"
	;;

armhf|armv7|riscv64)
	# skip uv related tests
	_test_filter="$_test_filter & !test(/^develop_[a-z0-9_]+::case_2$/)"
	# no idea why this fails
	_test_filter="$_test_filter & !test(~test_macosx_deployment_target)"
	;;
esac

prepare() {
	default_prepare

	cargo fetch --target="$CTARGET" --locked
}

build() {
	export OPENSSL_NO_VENDOR=1

	export MATURIN_SETUP_ARGS="--no-default-features $_features"

	gpep517 build-wheel \
		--wheel-dir .dist \
		--output-fd 3 3>&1 >&2

	./target/release/maturin completions bash > $pkgname.bash
	./target/release/maturin completions fish > $pkgname.fish
	./target/release/maturin completions zsh > $pkgname.zsh
}

check() {
	export OPENSSL_NO_VENDOR=1

	cargo nextest run \
	  --frozen \
	  --no-default-features "$_features" \
	  --no-fail-fast \
	  -E "$_test_filter"
}

package() {
	install -Dm644 $pkgname.bash "$pkgdir"/usr/share/bash-completion/completions/$pkgname
	install -Dm644 $pkgname.fish "$pkgdir"/usr/share/fish/vendor_completions.d/$pkgname.fish
	install -Dm644 $pkgname.zsh "$pkgdir"/usr/share/zsh/site-functions/_$pkgname

	python3 -m installer -d "$pkgdir" \
		.dist/maturin*.whl
}

py3() {
	pkgdesc="$pkgdesc (python module)"
	depends="$pkgname=$pkgver-r$pkgrel"

	amove usr/lib/python3*
}

sha512sums="
72fb43a10d3cdf35eca224232c59723bff5b9230c7d40ff01537e1ba869254b4b6e9a0c52e8b7154f7b74f0f0b5bace4e7bb9ac5257c9fbc04750160791c35e3  maturin-1.7.4.tar.gz
"
